package com.yu.newsSys.controller;

import com.yu.newsSys.constants.ListenerConstants;
import com.yu.newsSys.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class OnlineController {
    @RequestMapping("/online")
    @ResponseBody
    public Result ViewOnline(HttpServletRequest req) {
        // 读取servletContext中的onlineList集合，并返回给前端显示
        ServletContext context = req.getServletContext();
        List<String> onlineList = (List<String>) context.getAttribute(ListenerConstants.ONLINE_LIST);
        System.out.println("onlineList = " + onlineList);
        return Result.OK(onlineList);
    }
}
